/*Nama File : command.h
  Pembuat	: Karina Novita Suryani - 23512187 */

#include "command.h"

//empat sekawan
command::command(){	//ctor
	durSecond = 0;
}

command::command(string s, int durSec, DateTime dt)
//ctor berparameter
/* prekondisi : DateTime valid*/
{
	durSecond = durSec;
	
	tStart = dt;
	
	string tempStr = s;
	string p = s;
	int delim = p.find_first_of("# ,");
	while (delim != string::npos){
		p = tempStr.substr(0,delim);
		this->argument.push_back(p);
		tempStr = tempStr.substr(delim+1,tempStr.length()-delim+1);
		delim = tempStr.find_first_of("# ,");
	}
	
	this->argument.push_back(tempStr);
	
}

command::command(const command& C){	//cctor
	
	this->durSecond = C.durSecond;
	this->argument = C.argument;
	this->tStart = C.tStart;
}

command::~command(){	//dtor

	durSecond = 0;
	argument.clear();
}

command& command::operator=(const command& C){	//operator=

	this->durSecond = C.durSecond;
	this->tStart = C.tStart;
	
	this->argument.clear();
	this->argument = C.argument;
	
	return *this;
}

int operator== (const command& C1, const command& C2){	//overload operator kesamaan
	
	if (!(C1.argument[0].compare(C2.argument[0])) && (C1.argument.size() == C2.argument.size())){
		return 1;
	} else {
		return 0;
	}
	
}	

//setter
void command::setArgument(string argument)
/*I.S. sembarang*/
/*F.S. argument = argument*/
{
	
	this->argument.clear();
	
	string tempStr = argument;
	string p = argument;
	int delim = p.find_first_of("# ,");
	while (delim != string::npos){
		p = tempStr.substr(0,delim);
		this->argument.push_back(p);
		tempStr = tempStr.substr(delim+1,tempStr.length()-delim+1);
		delim = tempStr.find_first_of("# ,");
	}
	
	this->argument.push_back(tempStr);
}

void command::setDurSecond(int durationInSecond)
/*I.S. sembarang */
/*F.S. durSecond  = durInSecond */
{
	
	this->durSecond = durationInSecond;
}

void command::setTStart(DateTime dt)
/*I.S. sembarang */
/*F.S. tStart = dt */
{
	
	this->tStart = dt;
}
	
//getter
string command::getArgument(int i)
/*pre kondisi : argument tidak kosong*/
{
	return argument[i];
}

int command::getCountArgument()
/*pre kondisi : sembaran*/
{
	
	return argument.size();
}

int command::getDurSecond()
/*pre kondisi : sembaran*/
{
	
	return durSecond;
}

DateTime command::getTStart()
/*pre kondisi : sembaran*/
{

	return tStart;
}

//operasi tambahan
string command::ToString()
/*pre kondisi : sembaran*/
{

	string s = "";	
	DateTime tEnd = this->tStart;
	
	tEnd.AddTime(this->durSecond);
	
	s = this->tStart.ToString() + " - " + tEnd.ToString();
	
	
	for (int i = 0; i < this->argument.size(); i++){
		s = s + " ";
		s = s + this->argument[i];
	}
	
	return s;
}



